<template>
  <!--系统参数管理-->
  <section class="page system-parameter-manage">
    <data-form :model="queryModel" @handleResetForm="follFeedback" @onSearch="refreshData" autoSearch>
      <!--输入区域-->
      <template slot="inputs">
        <el-form-item label="批次号" prop="outBatch">
          <el-input v-model="queryModel.outBatch"></el-input>
        </el-form-item>
        <el-form-item label="订单编号" prop="caseNumber">
          <el-input v-model="queryModel.caseNumber"></el-input>
        </el-form-item>
        <el-form-item label="客户姓名" prop="personalName">
          <el-input v-model="queryModel.personalName"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="mobileNo">
          <el-input v-model="queryModel.mobileNo"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="queryModel.idCard"></el-input>
        </el-form-item>
        <el-form-item label="地区" prop="area">
          <el-input v-model="queryModel.area"></el-input>
          <!-- <el-cascader v-model="queryModel.area" :options="$city.getCityData()" 
          clearable></el-cascader>-->
        </el-form-item>
        <el-form-item label="催收员" prop="currentCollector">
          <el-input v-model="queryModel.currentCollector"></el-input>
        </el-form-item>
        <el-form-item label="案件金额" prop="caseMoney">
          <number-range :isInteger="true" v-model="queryModel.caseMoney"></number-range>
        </el-form-item>
        <el-form-item label="欠款金额" prop="outAmount">
          <number-range :isInteger="true" v-model="queryModel.outAmount"></number-range>
        </el-form-item>
        <el-form-item label="逾期期数" prop="overduePeriod">
          <el-select clearable placeholder="请选择" v-model="queryModel.overduePeriod">
            <el-option :key="index" :label="name" :value="code.replace(/M|\+/, '')" v-for="{index,name,code} in $dict.getDictData('OverduePeriodStatus')"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="逾期天数" prop="overdueDays">
          <number-range v-model="queryModel.overdueDays"></number-range>
        </el-form-item>
        <el-form-item label="行动代码" prop="FollowupBack">
          <el-select clearable placeholder="请选择" v-model="queryModel.followupBack">
            <el-option :key="index" :label="name" :value="code" v-for="{index,name,code} in $dict.getDictData('FollowupBack')"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="流转来源" prop="turnSource">
          <el-select clearable placeholder="请选择" v-model="queryModel.turnSource">
            <el-option :key="index" :label="name" :value="code" v-for="{index,name,code} in $dict.getDictData('TurnSource')"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品类型" prop="productCategory">
          <el-input v-model="queryModel.productCategory"></el-input>
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="queryModel.productName"></el-input>
        </el-form-item>
        <el-form-item label="案件流入时间" prop="followInTime">
          <el-date-picker :editable="false" clearable placeholder="选择日期时间" type="daterange" v-model="queryModel.followInTime"></el-date-picker>
        </el-form-item>
        <el-form-item label="案件标签" prop="labelName">
          <get-label-name :formModel="queryModel" v-model="queryModel.labelName"></get-label-name>
        </el-form-item>
      </template>
    </data-form>
    <data-box :data="dataList" :page="pageService" @onPageChange="refreshData">
      <template slot="columns">
        <!--数据列区域-->
        <el-table-column :min-width="$helper.getColumnWidth(6)" label="订单编号">
          <template slot-scope="scope">
            <el-button @click="openExecutionPage(scope.row)" type="text">{{scope.row.caseNumber}}</el-button>
          </template>
        </el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="批次号" prop="outBatch"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="客户姓名" prop="personalName"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="手机号" prop="mobileNo"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(7)" label="身份证号" prop="idCard"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(2)" label="地区" prop="area" show-overflow-tooltip></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="案件金额(元)" prop="caseMoney"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="欠款金额(元)" prop="overdueAmount"></el-table-column>
        <el-table-column :formatter="row => $common.isNotValue(row.overduePeriod) ? '':`M${row.overduePeriod}`" :min-width="$helper.getColumnWidth(3)" label="逾期期数" prop="overduePeriod"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="逾期天数" prop="overdueDays"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="产品类型" prop="productCategory"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)" label="产品名称" prop="productName"></el-table-column>
        <!-- <el-table-column prop="" label="顾客类型" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>-->
        <el-table-column :formatter="(row) => $filter.dictConvert(row.turnSource,'TurnSource')" :min-width="$helper.getColumnWidth(4)" label="流转来源" prop="turnSource"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(4)  " label="案件流入时间" prop="followInTime">
          <template slot-scope="scope">
            <span>{{scope.row.followInTime | dateTimeFormat}}</span>
          </template>
        </el-table-column>
        <el-table-column :formatter="(row) => $filter.dictConvert(row.followupBack,'FollowupBack')" :min-width="$helper.getColumnWidth(4)" label="行动代码" prop="followupBack"></el-table-column>
        <el-table-column :min-width="$helper.getColumnWidth(10)" label="案件标签" prop="labelName"></el-table-column>
      </template>
    </data-box>

    <el-dialog :center="true" :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="dialog.modifysysparamterDialog" @open="getmodifyData" title="修改">
      <modify-parameter @close="dialog.modifysysparamterDialog=false" @refreshList="refreshData" ref="refresh"></modify-parameter>
    </el-dialog>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Dependencies, Layout, Auth } from "~/core/decorator";

import NumberRange from "~/components/common/number-range.vue";

import { PageService } from "~/utils/page.service";
import { SortService } from "~/utils/sort.service";

import { OutsourceBackCService } from "~/services/domain-service/outsource-backc-manage.service";
import ModifyParameter from "~/components/system-manage/param-manage/modify-parameter.vue";
import { CityService } from "~/utils/city.service";
import { CASE_CHANNEL, MENU_CHANNEL } from "~/config/enum.config";
import { namespace } from "vuex-class";
import GetLabelName from "~/components/labeling-strategy/get-label-name.vue";

@Auth(1004)
@Layout("workspace")
@Component({
  components: {
    GetLabelName,
    NumberRange,
    ModifyParameter
  }
})
export default class BackCManageIndex extends Vue {
  @Dependencies(OutsourceBackCService)
  private outsourceBackCService: OutsourceBackCService;
  @Dependencies(PageService)
  private pageService: PageService;
  @Dependencies(SortService) private sortService: SortService;

  private queryModel: any = {
    outBatch: "",
    caseNumber: "",
    personalName: "",
    mobileNo: "",
    idCard: "",
    localAddress: "",
    currentCollector: "",
    overduePeriod: "",
    turnSource: "",
    FollowupBack: "",
    productCategory: "",
    productName: "",
    area: "",
    followupBack: "",
    outAmount: {
      max: "",
      min: ""
    },
    caseMoney: { min: "", max: "" },
    overdueDays: {
      max: "",
      min: ""
    },
    followInTime: [], //案件流入时间
    labelName: []
  };
  private proinviceList: any[] = []; // 省
  private cityList: any[] = []; //市

  private dataList: any[] = [];
  private dialog: any = {
    modifysysparamterDialog: false
  };
  private modifyData: any = {};
  private refresh: any = {};

  private mounted() {
    this.refreshData();
    this.getProvinces();
  }

  //获取省数据
  private getProvinces() {
    this.proinviceList = CityService.getCityData({ level: 1 });
  }

  //获取市
  private getCitys(provinceId) {
    if (this.queryModel.cityCode) {
      this.queryModel.cityCode = "";
    }
    this.cityList = this.$city.getCityData({ level: 1, id: provinceId }); // 城市列表
  }

  private refreshData() {
    this.outsourceBackCService
      .getCaseBackCPoolPageList(
        this.queryModel,
        this.pageService,
        this.sortService
      )
      .subscribe(data => {
        this.dataList = data;
      });
  }

  /**
   * 修改
   */
  private editDetail(scope) { }

  /**
   * 查看
   */
  private checkDetail(scope) { }

  /**
   * 修改open事件 ，获取要修改的当前行数据
   */
  private getmodifyData() {
    this.$nextTick(() => {
      this.refresh = this.$refs["refresh"];
      this.refresh.refresh(this.modifyData);
    });
  }

  /**
   * 进入查看执行页
   */
  private openExecutionPage(row) {
    this.$router.openCaseDetail(row.id, {
      menuChannel: MENU_CHANNEL.Outsource_turn,
      hiddenCaseList: true,
      hiddenAction: true
    });
  }

  /**
   * 重置numberRange
   */
  private follFeedback() {
    this.queryModel.outAmount = { min: "", max: "" };
    this.queryModel.overdueDays = { min: "", max: "" };
    this.queryModel.proinviceCode = "";
    this.queryModel.cityCode = "";
    this.queryModel.caseMoney = { min: "", max: "" };
  }
}
</script>

<style lang="less">
</style>
